from __future__ import annotations
from typing import List, Optional, Union

class PriceLevel:
    """订单栈"""
    price: float
    volume: int
    
    def __init__(self, price: float, volume: int) -> PriceLevel: ...
    def __repr__(self) -> str: ...

class TickData:
    """tick数据"""
    timestamp_us: int
    symbol: str
    last: float
    asks: List[PriceLevel]
    bids: List[PriceLevel]
    volumne: Optional[int]
    turnover: Optional[float]
    open_interest: Optional[float]
    
    def __init__(
        self,
        timestamp_us: int,
        symbol: str,
        last: float,
        asks: List[PriceLevel],
        bids: List[PriceLevel],
    ) -> TickData: ...
    
    def __repr__(self) -> str: ...

class Authority:
    """用户鉴权信息"""
    client_id: Optional[int]

    def __init__(self, client_id: Optional[int]) -> Authority: ...
    def __repr__(self) -> str: ...

class Direction:
    """交易方向枚举"""
    Long: Direction  # 多头
    Short: Direction  # 空头

class Currency:
    """货币倍率"""
    def rate(self) -> int: ...

class PositionEffect:
    """持仓操作枚举"""
    Open: PositionEffect    # 开仓
    Close: PositionEffect   # 平仓

class OrderStatus:
    """订单状态枚举"""
    Unfilled: OrderStatus        # 未成交
    PartiallyFilled: OrderStatus # 部分成交
    Filled: OrderStatus          # 完全成交
    Canceled: OrderStatus        # 已撤单
    Rejected: OrderStatus        # 拒绝
    Pending: OrderStatus         # 待处理

class Operation:
    """订单操作枚举"""
    Check: Operation   # 查询订单信息
    Cancel: Operation  # 撤销订单

class Order:
    """交易订单"""
    id: Optional[int]
    symbol: str
    direction: Direction
    position_effect: PositionEffect
    price: Optional[float]  # None表示市价单
    quantity: int
    status: OrderStatus
    timestamp_us: Optional[int]

    def __init__(
        self,
        symbol: str,
        direction: Direction,
        position_effect: PositionEffect,
        quantity: int,
        price: Optional[float] = None,
    ) -> Order: ...
    def set_id(self, id: int) -> None: ... # 通过客户端自行设置ID
    def __repr__(self) -> str: ...

class OrderOperation:
    """订单操作指令"""
    id: int
    operation: Operation

    def __init__(self, id: int, operation: Operation) -> OrderOperation: ...
    def __repr__(self) -> str: ...

class Position:
    """持仓信息"""
    symbol: str
    side: Direction
    cost: float
    quantity: int
    liquidatable: int
    def __repr__(self) -> str: ...

class Portfolio:
    """账户组合信息"""
    client_id: int
    positions: List[Position]
    balance: int
    balance_available: int
    currency: Currency
    def __repr__(self) -> str: ...

class BarData:
    """Bar数据 - 占位符实现"""
    
    def __init__(self) -> BarData: ...
    def __repr__(self) -> str: ...

collections = Union[TickData, Authority, Order, OrderOperation, Position, Portfolio, BarData, str]

class PyMessage:
    """Python消息包装器"""
    
    def __init__(self, obj: collections) -> PyMessage: ...
    
    @classmethod
    def query_account(cls) -> PyMessage: ...
    """创建一个QueryAccount消息"""
    
    @classmethod
    def subscribe_tick(cls, symbol: str) -> PyMessage: ...
    """创建一个订阅 Tick(Symbol) 的消息"""
    
    def to_binary_bytes(self) -> bytes: ...
    """将消息序列化为二进制字节数组"""
    
    @staticmethod
    def from_binary_bytes(bytes: bytes) -> PyMessage: ...
    """从二进制字节数组反序列化消息"""
    
    def get_data_type(self) -> str: ...
    """获取消息中包含的数据类型名称"""
    
    def get_data(self) -> Union[collections, None]: ...
    """获取消息中包含的数据对象，QueryAccount返回None"""
    
    def __repr__(self) -> str: ...